package com.zygh.policeasset.controller;

import com.zygh.policeasset.component.CommonResult;
import com.zygh.policeasset.pojo.RoadCross;
import com.zygh.policeasset.service.RoadCrossService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping({"/roadCross"})
@Api(tags = {"路口管理"})
@RestController
/* loaded from: police-asset-2.0-0.0.1-SNAPSHOT.jar:BOOT-INF/classes/com/zygh/policeasset/controller/RoadCrossController.class */
public class RoadCrossController {
    @Autowired
    RoadCrossService roadCrossService;

    @GetMapping({"/findByName"})
    @ApiOperation("通过名称查询路口信息(模糊查询)")
    public Object findByName(@RequestParam(defaultValue = "1", value = "pageNum") Integer pageNum, @RequestParam(defaultValue = "10", value = "pageSize") Integer pageSize, @RequestParam(value = "name", required = false) String name) {
        return this.roadCrossService.findByName(pageNum, pageSize, name);
    }

    @GetMapping({"/findByNameNoPage"})
    @ApiOperation("通过名称查询路口信息(模糊查询)不分页")
    public Object findByNameNoPage(@RequestParam(value = "name", required = false) String name) {
        return this.roadCrossService.findByNameNoPage(name);
    }

    @PutMapping({"/update"})
    @ApiOperation("修改")
    public Object update(@RequestBody RoadCross roadCross) {
        if (this.roadCrossService.update(roadCross).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("修改失败");
    }

    @PostMapping({"/add"})
    @ApiOperation("添加")
    public Object add(@RequestBody RoadCross roadCross) {
        if (this.roadCrossService.add(roadCross).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("添加失败");
    }

    @DeleteMapping({"/delete/{id}"})
    @ApiOperation("删除")
    public Object delete(@PathVariable Integer id) {
        if (this.roadCrossService.delete(id).intValue() > 0) {
            return new CommonResult().success();
        }
        return new CommonResult().validateFailed("删除失败");
    }
}